﻿using Ctrip.Demo.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Ctrip.Demo.ShenZhou
{
    public class ShenZhouOrderDemo : BaseDemo
    {
        private const string USER_Agent = "zuche/5.2.1 (iPhone; iOS 11.2.6; Scale/2.00)";

        private const int CID = 200521;

        private string uid;
        public ShenZhouOrderDemo(string uid)
        {
            this.uid = uid;
        }

        public override void Run()
        {
            //1、登录
            ShenZhouUser user = LoginIn();
            if (user == null)
            {
                return;
            }


        }

        protected ShenZhouUser LoginIn()
        {
            //{"uid":"13489082624","sdkVersion":"i_BT_BJ_2.0.0","deviceID":"91F4D269-FF0B-4DD7-81D2-85FEACD5C11A","ucarDeviceNo":"IOS_dd0057c6cf1b5fd6541755ca866551c5e48cdd280659d8fcd9438fd7bb3e6c29","lon":"121.351282","mobileType":"iPhone 6S","lat":"31.222182","pwd":"Pwd19891002.."}

            var obj = new
            {
                uid = "13489082624",
                sdkVersion = "i_BT_BJ_2.0.0",
                deviceID = "91F4D269-FF0B-4DD7-81D2-85FEACD5C11A",
                ucarDeviceNo = "IOS_dd0057c6cf1b5fd6541755ca866551c5e48cdd280659d8fcd9438fd7bb3e6c29",
                lon = "121.351282",
                lat = "31.222182",
                mobileType = "iPhone 6S",
                pwd = "Pwd19891002.."
            };

            string q = AES_128_CBC.Encrypt(JsonConvert.SerializeObject(obj));

            string reuslt = HttpUtil.Get(ShenZhouUrls.URL_LOGIN, new { cid = CID, event_id = 79, q = q, uid = uid }, USER_Agent);
            if (string.IsNullOrWhiteSpace(reuslt))
            {
                return null;
            }
            ShenZhouResponse<ShenZhouUser> response = JsonConvert.DeserializeObject<ShenZhouResponse<ShenZhouUser>>(reuslt);
            if (response == null)
            {
                return null;
            }
            if (response.Status != 0)
            {
                return null;
            }
            return response.Re;
        }


    }
}
